<?php
	/*********************用户登录功能模块***********************/

	header("Content-type:text/html;charset=utf-8");

	// 创建session
	session_start();

	// 连接数据库
	include("connect_db.php");

	$username = $_POST['username'];
	$password = md5($_POST['password']);

	//查询数据库
	$sql = mysql_query("SELECT * FROM user");
	$exits = false;

	while($rows = mysql_fetch_array($sql)){
		//用户名和密码存在
		if(($username == $rows['phone']) && ($password == $rows['pwd'])){
			//创建一个session变量

			$_SESSION['username'] = $rows['phone'];//保存此时登录的用户名
			$_SESSION['password'] = $rows['pwd']; //保存此时登录的用户密码

			// $login_res = array("login_res"=>true,"login_code"=>1,"login_msg"=>"登录成功");
			// $data = json_encode($login_res);
			$login = array("description"=>"登录成功","code"=>1,'msg'=>'用户名和密码都正确'); //用户名和密码正确

			$json = array("data"=>$login,"errcode"=>1,"errmsg"=>"ok");

			$data = json_encode($json);

			echo $data;
			$exits = true;
			//return;
		}
	}

	if(!$exits){//用户和密码不存在时的操作
		
		$login = array("description"=>"登陆失败","code"=>1,'msg'=>'用户名和密码不存在');

		$json = array("data"=>$login,"errcode"=>'-1','errmsg'=>'error');

		$data = json_encode($json);
		echo $data;
	}
	
	// $sql = mysql_query("SELECT * FROM user");
	// var_dump(mysql_fetch_array($sql));
	// echo 'hhah';
	// 85
?>